<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>待办事项-过渡效果</title>
  <style>
ul{
  list-style-type: none;
  padding:0;
}
ul input, ul label {
  cursor: pointer;
}
.done {
  text-decoration: line-through;
  color: #999;
}
.list-move {
  transition: transform 1s;
}
  </style>
</head>
<body>
  
<div id="app">
  <div>
    <input type="text" v-model="todo" @keyup.enter="add">
    <button @click="add">添加新计划</button>
  </div>
<transition-group name="list" tag="ul">
  <li v-for="item in todoList" :key="item.id">
    <input type="checkbox" :id="'todo-'+item.id" :checked="item.done" @click="check($event, item)"> 
    <label :for="'todo-'+item.id" :class="{'done': item.done}">{{item.todo}}</label>
  </li>
  <li v-for="item in doneList" :key="item.id">
    <input type="checkbox" :id="'todo-'+item.id" :checked="item.done" @click="check($event, item)"> 
    <label :for="'todo-'+item.id" :class="{'done': item.done}">{{item.todo}}</label>
  </li>
</transition-group>
</div>

<script src="vue.js"></script>
<script>
  var vm = new Vue({
    el: '#app',
    data:{
      todo: '',
      list: [
        { id: 1, todo: '去健身房健身', done: false, date: new Date() },
        { id: 2, todo: '去饭店吃饭', done: true, date: new Date() },
        { id: 3, todo: '去银行存钱', done: false, date: new Date() },
        { id: 4, todo: '去商场购物', done: false, date: new Date() }
      ]
    },
    computed: {
      todoList() {
        return this.list.filter(_ => _.done === false)
          .sort((a, b) => a.date - b.date)
      },
      doneList() {
        return this.list.filter(_ => _.done === true)
          .sort((a, b) => a.date - b.date)
      }
    },
    methods: {
      add() {
        if (!this.todo) return;
        this.list.push({id: this.list.length+1, todo: this.todo, done: false, date: new Date()});
        this.todo = '';
      },
      check(event, item) {
        item.done = event.target.checked
        item.date = new Date()
        console.log(item)
      },
    }
  })
</script>
</body>
</html>